package com.file;

import org.apache.commons.lang3.StringUtils;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;

/**
 * @author seven
 */
public class FieldLoad {

    private Integer count;
    /**
     * 获取文件byte[]
     * @param path
     * @return
     */
    public  byte[] getFileDataByte(String path){
        count = 1;
        if(StringUtils.isEmpty(path)){
            return null;
        }
        File file = new File(path);
        FileInputStream in = null;
        ByteArrayOutputStream out = null;
        try {
            in = new FileInputStream(file);
            out = new ByteArrayOutputStream();
            byte[] b = new byte[1024];
            int lineNum = 0;
            while((lineNum = in.read(b))!=-1){
                out.write(b,0,lineNum);
            }
            return out.toByteArray();
        }catch (Exception e){
            throw new RuntimeException(e);
        }finally {
            try {
                if(in != null){
                    in.close();
                }
                if(out != null){
                    out.close();
                }
            }catch (Exception e){
                System.out.println(".class文件读取出错");
                e.printStackTrace();
            }
        }
    }
}
